import { $umaHttp } from '../libs/axios.js'
import md5 from 'md5'
import apiUrl from './apiUrl'

let randomTime = ''
export default { 
  // 获取验证码
  getCaptcha() {
    randomTime = new Date().getTime()
    return apiUrl.getCaptcha + '?captchaHeader=' + randomTime
  },
  // 登录
  login(params) {
    const promise = new Promise(
      function (resolve, reject) {
        $umaHttp({
          method: 'post',
          url: apiUrl.login, 
          headers: {'captchaHeader': randomTime},
          data: {
            username: params.username,
            password: md5(params.password),
            captcha: params.captcha
          }}).then(res => {
          resolve(res.data);
        }) 
      });
    return promise;
  },
  // 退出登录
  logout() {
    const promise = new Promise(
      function (resolve, reject) {
        $umaHttp.post(apiUrl.logout).then(res => {
          resolve(res.data)
        }) 
      });
    return promise;
  },
  upload(params) {
    return apiUrl.upload;
  },
  getUploadFileName(params) {
    const promise = new Promise(
      function (resolve, reject) {
        $umaHttp.post(apiUrl.getUploadFileName + '?businessType=' + params.businessType + '&fileName=' + params.fileName).then(res => {
          resolve(res.data)
        }) 
      });
    return promise;
  },
  // 修改密码
  modifyPassword(params) {
    const promise = new Promise(
      function (resolve, reject) {
        $umaHttp.post(
          apiUrl.modifyPassword, 
            {
              username: params.username,
              password: md5(params.password),
              newPassword: md5(params.newPassword)
            }
          ).then(res => {
          resolve(res.data)
        }) 
      });
    return promise;
  },
  getRegionById(params) {
    const promise = new Promise(
      function (resolve, reject) {
        $umaHttp.post(apiUrl.getRegionById, params).then(res => {
          resolve(res.data)
        }) 
      });
    return promise;
  },
  /**
   * @description 资讯管理
   */
  advert: {
    // 获取列表
    getList(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.advert.getList, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getDetail(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.advert.getDetail + '?advertId=' + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    add(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.advert.add, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.advert.update, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    delete(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.advert.delete + '?advertId=' + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    onOffLine(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.advert.onOffLine, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getListPageCustomer(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.advert.getListPageCustomer, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getSort(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.advert.getSort + '?type=' + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
  /**
   * @description 学员管理
   */
  customer: {
    // 获取列表
    getList(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.customer.getList, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params) {
      const promise = new Promise(
        function (resolve, reject) {
          if(params.passWord) {
            params.passWord = md5(params.passWord)
          }
          $umaHttp.post(apiUrl.customer.update , params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getDetail(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.customer.getDetail + "?customerId=" + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    onExport(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.customer.onExport, params,{responseType: 'blob'}).then(res => {
            resolve(res.data)
          }) 

          // $umaHttp({
          //   method: 'post',
          //   url: apiUrl.customer.onExport, 
          //   // headers: {'captchaHeader': randomTime},
          //   data: params,
          //   responseType: 'blob'
          // }).then(res => {
          //     // resolve(res.data);
          //     let url = window.URL.createObjectURL(res)
          //   let link = document.createElement('a')
          //   link.style.display = 'none'
          //   link.href = url
          //   link.setAttribute('id', 'downloadLink')
          //   link.setAttribute('download', '残疾人信息表.xls')
          //   document.body.appendChild(link)
          //   link.click()
          //   // 删除添加的a链接
          //   let objLink = document.getElementById('downloadLink')
          //   document.body.removeChild(objLink)
          //   // 释放内存
          //   window.URL.revokeOjbectURL(url)
          // }) 
        });
      return promise;
    }
  },
  /**
   * @description 课程分类
   */
  courseType: {
    // 获取列表
    getList(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.courseType.getList, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getChildren(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.courseType.getChildren + '?parentCode=' + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    add(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.courseType.add, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.courseType.update, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    delete(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.courseType.delete + '?courseTypeId=' + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
  /**
   * @description 课程内容
   */
  course: {
    getList(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.course.getList, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getDetail(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.course.getDetail + '?courseInfoId=' + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    add(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.course.add, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.course.update, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    delete(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.course.delete + '?courseInfoId=' + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    onOffLine(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.course.onOffLine, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getSort(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.course.getSort + "?documentType=" + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
  /**
   * @description 等级规则
   */
  grade: {
    getList(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.grade.getList, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getDetail(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.grade.getDetail + '?gradeRuleId=' + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    add(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.grade.add, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.grade.update, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    delete(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.grade.delete + '?gradeRuleId=' + params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
  /**
   * @description 管理员管理用户
   */
  administrators: {
    getList(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.administrators.getList, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    add(params) {
      const promise = new Promise(
        function (resolve, reject) {
          if(params.passWord) {
            params.passWord = md5(params.passWord)
          }
          $umaHttp.post(apiUrl.administrators.add, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params) {
      const promise = new Promise(
        function (resolve, reject) {
          if(params.passWord) {
            params.passWord = md5(params.passWord)
          }
          $umaHttp.post(apiUrl.administrators.update, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
  /**
   * @description 报表
   */
  report: {
    courseLearnTimesReport(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.report.courseLearnTimesReport, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    courseReadTimesReport(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.report.courseReadTimesReport, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getCustomerForCourse(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.report.getCustomerForCourse, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    personalDateTimesReport(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.report.personalDateTimesReport, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    personalReport(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.report.personalReport, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    personalTimesReport(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.report.personalTimesReport, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
  qa: {
    getList(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.qa.getList, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    answer(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.qa.answer, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
  typeEnum: {
    getCompanyType() {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.typeEnum.getCompanyType).then(res => {
            resolve(JSON.parse(res.data.data))
          }) 
        });
      return promise;
    },
    getIndustryType() {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.typeEnum.getIndustryType).then(res => {
            resolve(JSON.parse(res.data.data))
          }) 
        });
      return promise;
    },
    getJobType() {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.typeEnum.getJobType).then(res => {
            resolve(JSON.parse(res.data.data))
          }) 
        });
      return promise;
    }
  },
   /**
   * @description 统计接口
   */
  statistics: {
    getTotalInfo() {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.statistics.getTotalInfo).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
  /**
   * @description brand
   */
  brand: {
    getList(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.brand.getList, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    getDetail(id) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.brand.getDetail + '?pageHomeId = ' + id).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params) {
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.brand.update, params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
  //友链增删改查
  blogroll:{ 
    getAllLinks(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.blogroll.getAllLinks,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    add(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.blogroll.add,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    delete(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.blogroll.delete,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.blogroll.update,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
  },
   //内链增删改查
   internalLink:{
    selectByPage(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.internalLink.selectByPage,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    add(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.internalLink.add,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.internalLink.update,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    delete(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.internalLink.delete,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
   },
   //聚合页面增删改查
   aggregation:{
    selectByPage(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.aggregation.selectByPage,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    update(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.aggregation.update,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    add(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.aggregation.add,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    delete(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.aggregation.delete,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    selectByEncryptId(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.aggregation.selectByEncryptId,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    }
   },
   //版权声明页面
   statement:{
    detail(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.statement.detail,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
    add(params){
      const promise = new Promise(
        function (resolve, reject) {
          $umaHttp.post(apiUrl.statement.add,params).then(res => {
            resolve(res.data)
          }) 
        });
      return promise;
    },
   }
}